import $ from 'jquery';
import 'popper.js';
import 'bootstrap';

import http from 'axios'

import { getQuery } from '../libs/tools'

http({
  method: 'GET',
  url: `http://localhost:3000/todos/${getQuery('id')}`,
}).then((res) => {
  const {data} = res
  $('.content-text').val(data.content)
})


$('#edit-todo').on('click', function () {
  http({
    method: 'PUT',
    url: `http://localhost:3000/todos/${getQuery('id')}`,
    data: {
      content: $('.content-text').val()
    }
  }).then((res) => {
    const {data} = res

    alert('修改成功')

    $('.content-text').val(data.content)
  })
})

$('#del-todo').on('click', function () {
  http({
    method: 'DELETE',
    url: `http://localhost:3000/todos/${getQuery('id')}`,
  }).then((res) => {
    const {data} = res

    alert('删除成功')

    location.href = 'index.html'
  })
})

